package com.wanxi.step07test.listener;


import com.wanxi.step07test.model.SUser;
import com.wanxi.step07test.service.impl.EmailService;
import com.wanxi.step07test.util.MailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class Listener {

    @Autowired
    EmailService emailService;

    @RabbitListener(queuesToDeclare = @Queue("admin"))
    public void SendEmailListener(List<SUser> emails){
        log.info("看这里的信息: {}","管理员的邮箱库已经接收");
        for (SUser sUser : emails) {
            try {
                emailService.sendEmail(sUser.getEmail(),"提醒你明天准时上班",sUser.getUsername()+"明天早点来上班");
            }catch (Exception e){
                e.printStackTrace();
            }

//            try {
//                MailUtil.sendMail(sUser.getEmail(),"提醒你明天准时上班",sUser.getUsername()+"明天早点来上班");
//            } catch (Exception e) {
//                e.printStackTrace();
//            }


        }


        log.info("看这里的信息: {}","上班通知全部发送");

    }
}
